<template>
  <div>
    <!--手工入库-->
    <cus-modal
      ref="modal"
      :showFullscreen="true"
      title="手工入库"
      :width="1350"
    >
      <cus-search style="margin: -30px 0 0 0">
        <cus-search-item>
          <Form :model="form" @keydown.native.enter.prevent="onInit">
            <FormItem
              label="供应商名称"
              prop="supplyId"
              :label-width="95"
              class="mr_48 mb_10"
            >
              <Select
                placeholder="全部"
                v-model="form.supplyId"
                @on-change="supplierChange"
                style="width: 200px"
              >
                <Option
                  v-for="item in supplierNameTree"
                  :value="item.id"
                  :key="item.id"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
            <div style="display:flex;">
              <cusButton
                class="ml_20 mr_20 mb_10"
                type="primary"
                v-if="data.length > 0"
                @onClick="onSave"
                style="width: 150px"
                >保存</cusButton
              >
              <cusButton
                class="mr_20 mb_10"
                type="primary"
                @onClick="onAddDetails()"
                style="width: 150px"
                >添加明细</cusButton
              >
              <!-- <cusButton
                class="mr_20 mb_10"
                type="error"
                @onClick="onAddDetails"
                style="width: 150px"
                >打印</cusButton
              > -->
            </div>
          </Form>
        </cus-search-item>
      </cus-search>
      <Table
        border
        :loading="loading"
        :columns="columns"
        :data="data"
        :size="vuex_config.tableSize"
        height="530"
      >
        <template slot-scope="{ row }" slot="operation">
          <div class="flex">
            <cus-button
              type="text"
              size="small"
              :style="{ color: '#1E6FFF' }"
              style="padding: 0 5px"
              @onClick="onEdit(row)"
            >
              <Icon
                type="md-color-filter"
                size="4"
                style="margin: 2px 5px 0 0"
              />
              <span>编辑</span>
            </cus-button>
            <cus-button
              type="text"
              size="small"
              :style="{ color: '#FF4746' }"
              style="padding: 0 5px"
              @onClick="onDelete(row)"
            >
              <Icon type="md-trash" size="4" style="margin: 2px 5px 0 0" />
              <span>删除</span>
            </cus-button>
          </div>
        </template>
      </Table>
      <div class="mt_20" v-if="data.length > 0" style="margin: 0 0 -10px 0">
        <cus-page
          :data="pages"
          class="mt_20 flex_jd"
          @pageChange="postApiGoodsHandaworkListApi()"
        ></cus-page>
      </div>
     <Spin size="large" fix v-if="spinShow"></Spin>
      <div slot="footer">
        <slot name="footer">
          <div class="modal-footer"></div>
        </slot>
      </div>
    </cus-modal>
    <!--手工入库物资登记 -->
    <Modal v-model="modal" width="1200" title="添加入库物资">
      <cus-search>
        <cus-search-item>
          <Form
            :model="manualForm"
            :label-width="95"
            @keydown.native.enter.prevent="onInit"
            style="width:100%; margin: -24px 0 0 0; display: flex; justify-content:space-between;"
          >
            <FormItem
              label="供应商名称"
              prop="supplyId"
              :label-width="95"
              class="mb_10"
            >
              <Select
                placeholder="全部"
                v-model="form.supplyId"
                disabled
                @on-change="supplierChange"
                style="width: 200px"
              >
                <Option
                  v-for="item in supplierNameTree"
                  :value="item.id"
                  :key="item.id"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="食材名称" class="mb_20">
              <Input
                clearable
                maxlength="20"
                placeholder="请输入食材名称"
                v-model="manualForm.name"
                style="width: 200px"
              />
            </FormItem>
            <FormItem label="食材种类" class="mb_20">
              <Select
                placeholder="全部"
                clearable
                v-model="manualForm.productClass"
                @on-change="
                  pagesTwo.page = 1;
                  postApiGoodsSelectBasProductListPageApi();
                "
                style="width: 200px"
              >
                <Option
                  v-for="item in productClassTree"
                  :value="item.name"
                  :key="item.id"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
            <cusButton class="ml_20" type="primary" @onClick="search"
              >查询</cusButton
            >
          </Form>
        </cus-search-item>
      </cus-search>
      <Table
        border
        :loading="manualForm.loading"
        :columns="columnsList"
        :data="dataList"
        height="530"
        :size="vuex_config.tableSize"
      >
        <template slot-scope="{ row }" slot="operation">
          <div class="flex">
            <cus-button
              type="text"
              size="small"
              :style="{ color: '#1E6FFF' }"
              style="padding: 0 5px"
              @onClick="onAdd(row)"
            >
              添加
            </cus-button>
          </div>
        </template>
      </Table>
      <div class="mt_10" style="margin: 0 0 -15px 0">
        <cus-page
          :data="pagesTwo"
          class="mt_10 flex_jd"
          @pageChange="postApiGoodsSelectBasProductListPageApi"
        ></cus-page>
      </div>
    </Modal>
    <!--添加入库量 编辑手工入库-->
    <Modal
      v-model="warehousingModal"
      width="420"
      @on-visible-change="onVisibleChange"
      :title="wareForm.name"
    >
      <Form
        :model="wareForm"
        :rules="ruleValidate"
        ref="formValidate"
        :label-width="125"
        @keydown.native.enter.prevent="onInit"
      >
        <FormItem label="物资种类:" prop="productClass" v-if="!flag" class="mr_24 mb_10">
          <Input
            :border="false"
            v-model.number="wareForm.productClass"
            style="width: 189px"
          />
        </FormItem>
        <FormItem label="物资名称:" prop="name" v-if="!flag" class="mr_24 mb_10">
          <Input
            :border="false"
            v-model.number="wareForm.name"
            style="width: 189px"
          />
        </FormItem>
        <!-- <FormItem label="是否自产:" class="mr_24 mb_10">
          <RadioGroup v-model="isProduced">
            <Radio :label="0">是</Radio>
            <Radio :label="1">否</Radio>
          </RadioGroup>
        </FormItem> -->
        <FormItem label="是否越库:" prop="isTheLibrary" class="mr_24 mb_10">
          <RadioGroup v-model="isTheLibrary">
            <Radio :label="1">是</Radio>
            <Radio :label="0">否</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="存储仓库:" prop="stockId" class="mr_24 mb_20">
          <Select
            placeholder="请选择"
            clearable
            v-model="wareForm.stockId"
            style="width: 189px"
          >
            <Option
              v-for="item in storehouseTree"
              :value="item.id"
              :key="item.id"
              >{{ item.name }}</Option
            >
          </Select>
        </FormItem>
        <FormItem label="计量单位:" prop="specification" class="mr_10 mb_20">
          <Select
            v-model="wareForm.specification"
            @on-change="specificationChange"
            :disabled="Boolean(isProduced)"
            style="width: 189px"
          >
            <Option
              v-for="item in unitTree"
              :value="item.value"
              :key="item.value"
            >
              {{ item.label }}</Option
            >
          </Select>
        </FormItem>
        <FormItem label="单位重量(Kg):" prop="unitWeight" class="mr_24 mb_20">
          <InputNumber
            :max="10000"
            :min="0"
            :precision="2"
            :disabled="unitWeightShow || !Edit || !flag || Boolean(isProduced)"
            v-model="wareForm.unitWeight"
            style="width: 189px"
          />
        </FormItem>
        <FormItem label="单价(元):" prop="packagingPrice" class="redDot mr_24 mb_20">
          <InputNumber
            :max="10000"
            :min="0"
            :disabled="Boolean(isProduced) || storageway == 10"
            v-model="wareForm.packagingPrice"
            style="width: 189px"
          />

        </FormItem>
        <FormItem label="入库量:" prop="packagingQty" class="redDot mr_24 mb_20">
          <InputNumber
            :max="10000"
            :min="0"
            maxlength="5"
            :precision="wareForm.weightFlag ? 2 : 0"
            v-model="wareForm.packagingQty"
            style="width: 189px"
            :active-change="false"
          />
        </FormItem>
      </Form>
      <div slot="footer">
        <slot name="footer">
          <div class="modal-footer">
            <cus-button size="small" class="mr_2" @onClick="warehousingonCancel"
              >取消</cus-button
            >
            <cus-button type="primary" size="small" @onClick="warehousingonOk"
              >确认</cus-button
            >
          </div>
        </slot>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  postApiGoodsHandaworkList,
  postApiGoodsSelectBasProductListPage,
  getApiGoodsHandaworkItem,
  getApiGoodsHandaworkSuppliername,
  postApiGoodsHandaworkSave,
  postApiGoodsHandaworkDelete,
  postApiGoodsHandaworkUpdate,
  postApiGoodsHandaworkSaveStockbill,
  getBasstockList,
  postApiGoodsStockbillSavepostockbll,
  postApiGoodsStockbillUpdatepostockbill
} from "@/api/business/manager";

const form = {
  id: "",
  supplierName: "", //供应商名称
  purchasingPlanName: "", //采购计划名称
  week: "" //供应时间节点value值
};
const columns = [
  {
    title: "序号",
    type: "index",
    minWidth: 70,
    align: "center"
  },
  {
    title: "物资名称",
    key: "name",
    minWidth: 100,
    align: "center"
  },
  {
    title: "物资类型",
    key: "productClass",
    minWidth: 100,
    align: "center"
  },
  {
    title: "数量",
    key: "packagingQty",
    minWidth: 80,
    align: "center"
  },
  {
    title: "单位重量(Kg)",
    key: "unitWeight",
    minWidth: 130,
    align: "center"
  },
  {
    title: "计量单位",
    key: "packagingUtil",
    minWidth: 100,
    align: "center"
  },
  {
    title: "单价(元)",
    key: "packagingPrice",
    minWidth: 90,
    align: "center"
  },
  {
    title: "金额(元)",
    key: "amount",
    minWidth: 90,
    align: "center"
  },
  {
    title: "存储仓库",
    key: "stockName",
    minWidth: 100,
    align: "center"
  },
  {
    title: "创建时间",
    key: "createTime",
    minWidth: 125,
    align: "center"
  },
  {
    title: "是否自产",
    key: "isProduced",
    minWidth: 100,
    align: "center",
    render: (h, params) => {
      return h("div", [
        h("span", {}, params.row.isProduced == 0 ? "是" : "否")
      ]);
    }
  },
  {
    title: "备注",
    key: "remark",
    minWidth: 80,
    align: "center"
  },
  {
    title: "操作",
    slot: "operation",
    minWidth: 135,
    fixed: "right",
    align: "center"
  }
];
const manualForm = {
  loading: false,
  supplyId: "", //供应商id
  py: "", //拼音首字母
  name: "", //食材名称
  productClass: "", //食材种类
  supplierName: "" //供应商名称
};
const wareForm = {
  id: "",
  productId: "", //物资id
  stockId: "", //仓库id
  name: null, //食材名称
  productClass: null, //物资种类
  specification: null, //规格
  unitWeight: null, //单位重量
  packagingPrice: 0, //价格
  // qty: 0, //入库数量
  packagingQty: 0, //入库数量
  storageway: null, //仓库
  weightFlag: null, //是否称重标识
  productType: null //根据菜肴或食材排序
};
const columnsList = [
  {
    title: "序号",
    type: "index",
    minWidth: 70,
    align: "center"
  },
  {
    title: "食材名称",
    key: "name",
    minWidth: 100,
    align: "center"
  },
  {
    title: "食材种类",
    key: "productClass",
    minWidth: 100,
    align: "center"
  },
  {
    title: "计量单位",
    key: "model",
    minWidth: 100,
    align: "center"
  },
  {
    title: "单位重量(Kg)",
    key: "unitWeight",
    minWidth: 120,
    align: "center"
  },
  {
    title: "单价(元)",
    key: "packagingPrice",
    minWidth: 100,
    align: "center"
  },
  {
    title: "是否称重出入库",
    key: "weightFlag",
    minWidth: 105,
    align: "center"
  },
  {
    title: "商品码",
    key: "snCode",
    minWidth: 135,
    align: "center"
  },
  {
    title: "品牌",
    key: "brand",
    minWidth: 90,
    align: "center"
  },
  {
    title: "操作",
    slot: "operation",
    minWidth: 135,
    fixed: "right",
    align: "center"
  }
];
const unitTree = [
  //规格selecttree数据
  {
    value: 0,
    label: "公斤"
  },
  {
    value: 1,
    label: "斤"
  },
  {
    value: 2,
    label: "件"
  },
  {
    value: 3,
    label: "箱"
  },
  {
    value: 4,
    label: "袋"
  },
  {
    value: 5,
    label: "瓶"
  },
  {
    value: 6,
    label: "桶"
  },
  {
    value: 7,
    label: "盒"
  },
  {
    value: 8,
    label: "个"
  },
  {
    value: 9,
    label: "把"
  },
  { value: 10, label: "包" },
  { value: 11, label: "罐" },
  { value: 12, label: "份" },
  { value: 13, label: "只" },
  { value: 14, label: "组" },
  { value: 15, label: "条" },
  { value: 16, label: "杯" },
  { value: 17, label: "升" }
];
export default {
  components: {},
  data() {
    return {
      spinShow:false,
      loading: false,
      ruleValidate: {
        packagingPrice: this.$cu.test.precision({
          require: true,
          message: "价格不能为空"
        }),
        packagingQty: this.$cu.test.precision({
          require: true
        })
      },
      form: form, //手工入库form表单
      columns: columns, //手工入库表头
      data: [], //手工入库表数据
      modal: false, //添加明细模态框状态
      manualForm: manualForm, //物资登记form表单
      supplierNameTree: [], //供应商名称selectTree数据
      productClassTree: [], //食材种类selectTree数据
      columnsList: columnsList, //物资登记表头
      dataList: [], //物资登记数据
      warehousingModal: false, //添加入库量模态框
      wareForm, //添加入库量
      isProduced: 0, //是否自产
      isTheLibrary: 0, //是否越库
      unitWeightShow: false, //规格与单位禁选状态
      unitTree: unitTree, //规格select,tree数据
      storehouseTree: [], //仓库select tree数据
      editModal: false, //编辑手工入库模态框状态
      billNo: "", //采购单号
      flag: false, //是否展示物资种类,物资名称标识,添加展示,编辑不展示
      Edit: false, //Edit:true添加,false,修改
      storageway: '', //入库方式
      pages: {
        //手工入库分页
        page: 1,
        pageSize: 10,
        pageTotal: 0
      },
      pagesTwo: {
        //手工入库物资登记分页
        page: 1,
        pageSize: 10,
        pageTotal: 0
      }
    };
  },
  props: {
    isEdit: {
      //isEdit:true,明细添加,false,手工添加
      type: Boolean,
      default: false
    }
  },
  mounted() {},
  methods: {
    onVisibleChange(v) {
      if(!v) {
        this.flag = false;
        this.Edit = false;
        this.warehousingonCancel()
      }
      this.$refs["formValidate"].resetFields();
    },
    show() {
      this.loading = false;
      this.$refs["modal"].show = true;
      this.postApiGoodsHandaworkListApi();
      this.getApiGoodsHandaworkSuppliernameApi();
      this.getApiGoodsHandaworkItemApi();
    },
    //查询
    search() {
      this.pagesTwo.page = 1;
      this.postApiGoodsSelectBasProductListPageApi();
    },
    //供应商选择
    supplierChange(v) {
      console.log(v);
    },
    //添加明细
    onAddDetails() {
      this.modal = true;
      this.isEdit = false;
      this.postApiGoodsSelectBasProductListPageApi();
    },
    //编辑明细
    onEdit(row) {
      console.log('对象',row);
      this.getBasstockListApi(); //获取物资仓库列表
      this.flag = false;
      this.wareForm = JSON.parse(JSON.stringify(row));
      this.isProduced = row.isProduced;
      this.isTheLibrary = row.isTheLibrary;
      this.wareForm.packagingQty = JSON.parse(JSON.stringify(row.packagingQty));
      this.wareForm.packagingPrice = JSON.parse(JSON.stringify(row.packagingPrice));
      this.wareForm.weightFlag = row.product.weightFlag;
      this.warehousingModal = true;
    },
    textChange(v) {
      let value = v + "";
      // 是否称重出入库判断，是可以输入小数
      if (this.wareForm.weightFlag == "否") {
        this.wareForm.packagingQty = Number(value.replace(/[^\d]/g, ""));
      }
    },
    //删除明细
    onDelete(row) {
      this.$cu
        .dialog({
          params: row
        })
        .then(({ id }) => {
          this.postApiGoodsHandaworkDeleteApi(id);
        });
    },
    //添加入库物资数量/重量明细按钮
    onAdd(row) {
      console.log('对象',row);
      this.flag = true;
      this.Edit = true;
      this.warehousingModal = true; //弹框状态
      console.log('添加------------');
      console.log(this.flag,this.Edit);
      this.getBasstockListApi(); //获取物资仓库列表
      this.$nextTick(() => {
        this.wareForm.specification = JSON.parse(
          JSON.stringify(row.specification)
        ); //规格
        this.wareForm.unitWeight = JSON.parse(JSON.stringify(row.unitWeight)); //单位重量
        this.wareForm.id = JSON.parse(JSON.stringify(row.id)); //物资id
        this.wareForm.name = JSON.parse(JSON.stringify(row.name)); //名称
        this.wareForm.packagingPrice = JSON.parse(JSON.stringify(row.packagingPrice)); //价格
        this.wareForm.stockId = JSON.parse(JSON.stringify(row.intentStockId)); //存储仓库id,intentStockId代表拟入库,StockId代表实际入库
        // this.wareForm.weightFlag = JSON.parse(JSON.stringify(row.weightFlag));
        this.wareForm.weightFlag = row.weightFlag == "是" ? true : false;
      });
      this.isProduced = 1; //默认是否自产
      if (row.model == "公斤" || row.model == "斤") {
        this.unitWeightShow = true;
      } else {
        this.unitWeightShow = false;
      }
    },
    //保存入库按钮
    onSave() {
      if (
        this.form.supplyId != "" &&
        this.form.supplyId != null &&
        this.form.supplyId != undefined
      ) {
        this.postApiGoodsHandaworkSaveStockbillApi();
      } else {
        this.$Message.error("请选择供应商");
      }
    },
    //规格选择换算单位重量
    specificationChange(value) {
      if (value === 0) {
        this.wareForm.unitWeight = 1;
        this.unitWeightShow = true;
      }
      if (value === 1) {
        //规格为斤时，单位重量默认0.5
        this.wareForm.unitWeight = 0.5;
        this.unitWeightShow = true;
      }
      if (value != 0 && value != 1) {
        this.wareForm.unitWeight = 1;
        this.unitWeightShow = false;
      }
    },
    //添加手工入库物资登记模态框确认按钮
    warehousingonOk() {
      this.$refs["formValidate"].validate(valid => {
        if (valid) {
          if (this.isEdit == true) {
            console.log(this.Edit);
            if (this.Edit == true) {
              this.postApiGoodsStockbillSavepostockbllApi();
              console.log("详情", "add");
            } else {
              this.postApiGoodsStockbillUpdatepostockbillApi();
              console.log("详情", "edit");
            }
          } else {
            if (this.flag) {
              if (this.wareForm.packagingPrice != 0) {
                this.postApiGoodsHandaworkSaveApi();
              } else {
                this.$Message.error("价格不能为0");
              }
              console.log("手工add");
            } else {
              console.log("手工edit");
              this.postApiGoodsHandaworkUpdateApi();
            }
          }
        }
      });
    },
    //手工入库登记明细------------------------------接口
    postApiGoodsSelectBasProductListPageApi() {
      this.manualForm.loading = true;
      return new Promise(resolve => {
        let params = {
          name: this.manualForm.name, //拼音首字母
          productClass: this.manualForm.productClass, //食材名称
          py: this.manualForm.py, //食材种类
          supplyId: this.form.supplyId, //供应商id
          current: this.pagesTwo.page,
          size: this.pagesTwo.pageSize
        };
        postApiGoodsSelectBasProductListPage(params).then(res => {
          this.manualForm.loading = false;
          if (res.retCode === 2000) {
            this.dataList = res.data.records;
            this.dataList.forEach(element => {
              element.weightFlag = element.weightFlag ? "是" : "否";
            });
            this.pagesTwo.pageTotal = res.data.total;
            resolve();
          } else {
            this.manualForm.loading = false;
          }
        });
      });
    },
    //添加手工入库物资登记模态框取消按钮
    warehousingonCancel() {
      this.isProduced = 0;
      //是否自
      this.isTheLibrary = 0;

      //是否越库
      this.wareForm.packagingQty = 0;

      //入库量
      this.warehousingModal = false;
    },
    //添加手工登记物资明细-------------接口
    postApiGoodsHandaworkSaveApi() {
      return new Promise(resolve => {
        let params = {
          productId: this.wareForm.id, //物资id
          isProduced: this.isProduced, //是否自产 0 (是) 1 (否)
          specification: this.wareForm.specification, //规格 0 (‘公斤’) 1 (‘件，瓶，箱，桶’)
          unitWeight: this.wareForm.unitWeight, //单位重量
          packagingQty: this.wareForm.packagingQty, //入库数量  (数据传给后端乘以1000，显示除以1000)
          packagingPrice: this.wareForm.packagingPrice, //价格 (数据传给后端乘以1000，显示除以1000)
          stockId: this.wareForm.stockId, //仓库id，
          isTheLibrary: this.isTheLibrary, //是否越库 0 (是) 1 (否)
          // packagingQty: this.wareForm.packagingQty //入库重量
        };
        postApiGoodsHandaworkSave(params).then(res => {
          if (res.retCode === 2000) {
            this.pages.page = 1;
            this.postApiGoodsHandaworkListApi();
            this.$Message.success(res.retMsg);
            this.warehousingModal = false;
            resolve();
          }
        });
      });
    },
    //获取物资食材种类-----------------接口
    getApiGoodsHandaworkItemApi() {
      return new Promise(resolve => {
        getApiGoodsHandaworkItem().then(res => {
          if (res.retCode === 2000) {
            this.productClassTree = res.data;
            resolve();
          }
        });
      });
    },
    //获取物资食材供应商名称--------------接口
    getApiGoodsHandaworkSuppliernameApi() {
      return new Promise(resolve => {
        getApiGoodsHandaworkSuppliername().then(res => {
          if (res.retCode === 2000) {
            this.supplierNameTree = res.data;
            if (res.data) {
              this.form.supplyId = res.data[0].id;
              this.manualForm.supplyId = res.data[0].id;
            }
            resolve();
          }
        });
      });
    },
    //手工入库添加列表数据-------------接口
    postApiGoodsHandaworkListApi() {
      return new Promise(resolve => {
        let params = {
          current: this.pages.page,
          size: this.pages.pageSize
        };
        postApiGoodsHandaworkList(params).then(res => {
          if (res.retCode === 2000) {
            this.data = res.data.records;
            this.data.forEach(element => {
              element.name = element.product.name;
              element.productClass = element.product.productClass;
            });
            this.pages.pageTotal = res.data.total;
            resolve();
          }
        });
      });
    },
    //编辑手工明细-----------------------接口
    postApiGoodsHandaworkUpdateApi() {
      return new Promise(resolve => {
        let params = {
          id: this.wareForm.id,
          productId: this.wareForm.productId, //id仓库id
          isProduced: this.isProduced, //是否自产
          isTheLibrary: this.isTheLibrary, //是否越库
          packagingPrice: this.wareForm.packagingPrice, //价格
          packagingQty: this.wareForm.packagingQty, //入库量
          stockId: this.wareForm.stockId, //仓库id，
          specification: this.wareForm.specification, //规格
          unitWeight: this.wareForm.unitWeight //单位重量
        };
        postApiGoodsHandaworkUpdate(params).then(res => {
          if (res.retCode === 2000) {
            this.pages.page = 1;
            this.postApiGoodsHandaworkListApi();
            this.$Message.success(res.retMsg);
            this.warehousingModal = false;
            resolve();
          } else {
            this.warehousingModal = false;
          }
        });
      });
    },
    //删除手工明细-----------------------接口
    postApiGoodsHandaworkDeleteApi(id) {
      return new Promise(resolve => {
        postApiGoodsHandaworkDelete({
          id: id
        }).then(res => {
          if (res.retCode == 2000) {
            this.$Message.success(res.retMsg);
            this.postApiGoodsHandaworkListApi();
          }
          resolve();
        });
      });
    },
    //保存手工入库
    postApiGoodsHandaworkSaveStockbillApi() {
      return new Promise(resolve => {
        let params = {
          supplyId: this.form.supplyId
        };
        this.spinShow = true;
        postApiGoodsHandaworkSaveStockbill(params).then(res => {
          this.spinShow = false;
          if (res.retCode === 2000) {
            this.$Message.success(res.retMsg);
            this.$refs["modal"].show = false;
            this.$parent.getGoodsStockbilListApi();
            resolve();
          }
        });
      });
    },
    //物资仓库列表---------接口
    getBasstockListApi() {
      this.storehouseTree = [];
      return new Promise(resolve => {
        let params = {
          orderType: this.wareForm.productType, //默认排序
          current: 1,
          size: 1000
        };
        getBasstockList(params).then(res => {
          console.log('调取接口',res);
          if (res.retCode == 2000) {
            res.data.records.forEach(element => {
              // deleted = 0; 启用的仓库
              if (element.deleted === 0) {
                this.storehouseTree.push(element);
                if (element.defaultStock === 1 && (this.Edit || this.flag)) {
                  console.log("*--------/", element.id);
                  this.wareForm.stockId = element.id; // 默认仓库
                }
              }
            });
            resolve();
          }
        });
      });
    },
    //物资入库验收详情添加明细-添加入库量-------接口
    postApiGoodsStockbillSavepostockbllApi() {
      console.log("=======", this.wareForm.stockId);
      return new Promise(resolve => {
        let params = {
          billNo: this.billNo, //采购单号
          productId: this.wareForm.id, //物资id
          isProduced: this.isProduced, //是否自产
          isTheLibrary: this.isTheLibrary, //是否越库
          packagingPrice: this.wareForm.packagingPrice, //价格
          packagingQty: this.wareForm.packagingQty, //入库量
          specification: this.wareForm.specification, //规格
          unitWeight: this.wareForm.unitWeight, //单位重量
          stockId: this.wareForm.stockId //仓库id
        };
        postApiGoodsStockbillSavepostockbll(params).then(res => {
          if (res.retCode === 2000) {
            this.pages.page = 1;
            this.$parent.postApiGoodsStockbillGetApi();
            this.$Message.success(res.retMsg);
            this.warehousingModal = false;
            resolve();
          } else {
            this.warehousingModal = false;
          }
        });
      });
    },
    //物资入库验收详情添加明细-编辑入库量-------接口
    postApiGoodsStockbillUpdatepostockbillApi() {
      return new Promise(resolve => {
        let params = {
          billNo: this.billNo, //采购单号
          productId: this.wareForm.productId, //物资id
          stockId: this.wareForm.stockId, //仓库id
          id: this.wareForm.id,
          isProduced: this.isProduced, //是否自产
          isTheLibrary: this.isTheLibrary, //是否越库
          packagingPrice: this.wareForm.packagingPrice, //价格
          packagingQty: this.wareForm.packagingQty, //入库量
          specification: this.wareForm.specification, //规格
          unitWeight: this.wareForm.unitWeight //单位重量
        };
        postApiGoodsStockbillUpdatepostockbill(params).then(res => {
          if (res.retCode === 2000) {
            this.pages.page = 1;
            this.$parent.postApiGoodsStockbillGetApi();
            this.$Message.success(res.retMsg);
            this.warehousingModal = false;
            resolve();
          } else {
            this.warehousingModal = false;
          }
        });
      });
    }
  }
};
</script>

<style lang="less" scoped>
//物资表单 label-position="top"
.materials {
  /deep/.ivu-form-item-label {
    display: flex;
    justify-content: flex-start !important;
  }
}
.redDot {
  /deep/.ivu-form-item-label:before {
    content: "";
    margin-right: 0px;
  }
}
</style>
